<?php

    class UserListEngine
    {
		private $dbProvider;
        
        public function __construct()
        {
			$this->dbProvider = new UserDataProvider();
        }
        
        public function showUsers()
        {
			$navigation = new NavigationEngine("users", 0);
			$page = $navigation->getPage();

			$start = ( ( USER_AMOUNT * $page ) - USER_AMOUNT );
            
            $users = $this->dbProvider->getUserListFromDb( $start, USER_AMOUNT );
			
            if ( $users )
            {
                $i = 0;
				$list = array();
				
                while ( $i < USER_AMOUNT )
                {
                    if ( $i >= count( $users ) ) break;
					$list[$i]['link'] = "get_user_info.php?id=".$users[$i]['user_id'];
					$list[$i]['email'] = $users[$i]['email'];
					$list[$i]['first'] = $users[$i]['first_name'];
					$list[$i]['last'] = $users[$i]['last_name'];
                    
                    ++$i;
                }
               
				$pages = array();
				if ($navigation->getPageNum() == 1)
				{
					$pages = $navigation->printOnePage();
				}
				else if ( $page == 1)
				{
					$pages = $navigation->printFirstPart();
				}
				else if ($page == $navigation->getPageNum() )
				{
					$pages = $navigation->printLastPart();
				}
				else
				{
					$pages = $navigation->printMiddlePart( $page );
				}
				$vars = array( 
								'userList' => $list,
								'pages' => $pages,
							  );
				
				$vars['navigation'] = getView('templates/navigation.tpl', $vars);
				return getView('templates/user_list.tpl', $vars);
            }
        }
    }

?>